import { SecTimer } from "../../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../../com/gengine/core/frame/TimerType";
import { SMagicTowerInfo } from "../../../../../Message/Public/SMagicTowerInfo";
import { TMagicTowerConfig } from "../../../../../Message/Db/Tables/TMagicTowerConfig";
import { TCopy } from "../../../../../Message/Db/Tables/TCopy";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { Cache } from "../../../cache/Cache";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { ImagesConst } from "../../../resource/ImagesConst";
import { MagicTowerAwardItems } from "./MagicTowerAwardItems";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { BossConfig } from "../../../resource/BossConfig";
import { RemainTimeTool } from "../../award/RemainTimeTool";
import { ItemData } from "../../../resource/info/ItemData";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
import { _remainSec } from "../../../../../this/_remainSec";
type int = number;
//class TowerPassConditionPanel
    
    export  class TowerPassConditionPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.mouseEnabled = false;
            this.createChildren();
            return;
        }

        protected startTimer(): void
        {
            if (!this._secTimer) 
            {
                this._secTimer = new SecTimer();
                this._secTimer.addListener(TimerType.ENTERFRAME, this.onSecTimerEvent);
            }
            if (!this._secTimer.running) 
            {
                this._secTimer.start();
            }
            return;
        }

        public updateInfos(arg1: SMagicTowerInfo, arg2: TMagicTowerConfig, arg3: TCopy, arg4: Boolean): void
        {
            var loc1=0;
            this._hasPass = false;
            if (arg1 && arg2 && arg3) 
            {
                loc1 = arg1.totalBossNum - arg1.killBossNum;
                if (arg1.floor > 0 && loc1 <= 0) 
                {
                    this._hasPass = true;
                }
                this._warFareLabel.htmlText = "";
                this._condition.htmlText = HTMLUtil.addColor(Language.getString(60360), "#FFFF00") + (this._hasPass ? HTMLUtil.addColor(Language.getString(60073), "#FF7902") : "");
                this._conditionLabel.htmlText = this.getConditionText(arg2);
                this._tipsLabel.htmlText = this.getTipsText(arg1, arg2);
                this._topTimeLabel.htmlText = this.getTopTimeText(arg1, arg2);
                this._remainBossLabel.htmlText = this.getRemainBossText(arg1, arg2);
                this._expAward.htmlText = HTMLUtil.addColor(Language.getString(60361), "#FFFF00") + "\n";
                this._expAwardText.htmlText = this.getAwardExpText(arg1, arg2);
                if (arg2.awardItems == "") 
                {
                    this._itemAwardText.htmlText = "";
                    this._itemAward.setAwardItems([]);
                }
                else 
                {
                    this._itemAwardText.htmlText = HTMLUtil.addColor(Language.getString(60362), "#FFFF00");
                    this._itemAward.setAwardItems(this.getAwardItems(arg2));
                }
                if (!(arg2.firstReward == "") && Cache.instance.copy.getCopyMaxFirstRewardProcess(arg3.code) < arg1.floor) 
                {
                    this._splitLine2.visible = true;
                    this._firstKillAwardText.htmlText = HTMLUtil.addColor(Language.getString(60476), "#FFFF00");
                    this._firstKillAward.setAwardItems(this.getFirstAwardItems(arg2));
                }
                else 
                {
                    this._splitLine2.visible = false;
                    this._firstKillAwardText.htmlText = "";
                    this._firstKillAward.setAwardItems([]);
                }
                if (arg1.resetTime || arg4 || !this._secTimer || !this._secTimer.running) 
                {
                    this._useSec = arg1.useSec;
                    this._remainSec = arg1.remainSec;
                    this.updateTimeLabel();
                    this.startTimer();
                }
                if (arg1.totalBossNum > 0 && arg1.killBossNum == arg1.totalBossNum) 
                {
                    this._useSec = arg1.useSec;
                    this._remainSec = arg1.remainSec;
                    this.updateTimeLabel();
                    this.stopTimer();
                }
            }
            else 
            {
                this.clear();
            }
            this.updatePosition();
            return;
        }

        protected createChildren(): void
        {
            this._bg = new Object /* flash.display.Bitmap */(new Object /* flash.display.BitmapData */(260, 200, false, 0));
            this._bg.alpha = 0.45;
            this.addChild(this._bg);
            this._bodySp = new Object /* flash.display.Sprite */();
            this._bodySp.mouseEnabled = false;
            this.addChild(this._bodySp);
            this._warFareLabel = ObjCreate.createTextField("", this._left, 0, 250, 20, this._bodySp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            this._warFareLabel.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._warFareLabel.mouseEnabled = false;
            this._condition = ObjCreate.createTextField("", this._left, 0, 250, 20, this._bodySp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            this._condition.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._condition.mouseEnabled = false;
            this._conditionLabel = ObjCreate.createTextField("", this._left + 30, 0, 215, 20, this._bodySp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            this._conditionLabel.multiline = true;
            this._conditionLabel.wordWrap = true;
            this._conditionLabel.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._conditionLabel.mouseEnabled = false;
            this._tipsLabel = ObjCreate.createTextField("", this._left + 30, 0, 250, 20, this._bodySp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            this._tipsLabel.multiline = true;
            this._tipsLabel.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._tipsLabel.mouseEnabled = false;
            this._passedTimeLabel = ObjCreate.createTextField("", this._left, 0, 250, 20, this._bodySp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            this._passedTimeLabel.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._passedTimeLabel.mouseEnabled = false;
            this._remainTimeLabel = ObjCreate.createTextField(Language.getString(60081), this._left, 0, 250, 20, this._bodySp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            this._remainTimeLabel.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._remainTimeLabel.mouseEnabled = false;
            this._remainTime = ObjCreate.createTextField("", this._left + 84, 0, 250, 20, this._bodySp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            this._remainTime.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._remainTime.mouseEnabled = false;
            this._topTimeLabel = ObjCreate.createTextField("", this._left, 0, 250, 20, this._bodySp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            this._topTimeLabel.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._topTimeLabel.mouseEnabled = false;
            this._remainBossLabel = ObjCreate.createTextField("", this._left, 0, 250, 20, this._bodySp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            this._remainBossLabel.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._remainBossLabel.mouseEnabled = false;
            this._splitLine = ObjCreate.createBg(this._left, 0, 250, 2, this, ImagesConst.SplitLine);
            this._expAward = ObjCreate.createTextField("", this._left, 0, 250, 20, this._bodySp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            this._expAward.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._expAward.mouseEnabled = false;
            this._expAwardText = ObjCreate.createTextField("", this._left + 30, 0, 250, 20, this._bodySp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            this._expAwardText.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._expAwardText.multiline = true;
            this._expAwardText.mouseEnabled = false;
            this._itemAwardText = ObjCreate.createTextField("", this._left, 0, 250, 20, this._bodySp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            this._itemAwardText.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._itemAwardText.mouseEnabled = false;
            this._itemAward = new MagicTowerAwardItems();
            this._itemAward.x = this._left + 40;
            this._bodySp.addChild(this._itemAward);
            this._splitLine2 = ObjCreate.createBg(this._left, 0, 250, 2, this, ImagesConst.SplitLine);
            this._firstKillAwardText = ObjCreate.createTextField("", this._left, 0, 250, 20, this._bodySp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            this._firstKillAwardText.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._firstKillAwardText.mouseEnabled = false;
            this._firstKillAward = new MagicTowerAwardItems();
            this._firstKillAward.x = this._left + 40;
            this._bodySp.addChild(this._firstKillAward);
            return;
        }

        /* internal  */getConditionText(arg1: TMagicTowerConfig): string
        {
            var loc1="";
            loc1 = loc1 + HTMLUtil.addColor(arg1.describe, GlobalStyle.color1);
            return "<textFormat leading=\'5\'>" + loc1 + "</textFormat>";
        }

        /* internal  */getWarFareText(arg1: TMagicTowerConfig): string
        {
            return HTMLUtil.addColor(Language.getString(60363) + arg1.warfare, "#FFFF00");
        }

        /* internal  */getTipsText(arg1: SMagicTowerInfo, arg2: TMagicTowerConfig): string
        {
            var loc1="";
            if (arg1.floor > 0 && arg2.haveBoss == 1 && (!(arg2.addBossId == 0) || !(arg2.delBossId == 0))) 
            {
                loc1 = loc1 + Language.getString(60074);
                if (arg2.addBossId != 0) 
                {
                    loc1 = loc1 + (Language.getStringByParam(60075, BossConfig.instance.getInfoByCode(arg2.addBossId).boss.name) + "\n");
                }
                if (arg2.delBossId != 0) 
                {
                    loc1 = loc1 + Language.getStringByParam(60076, BossConfig.instance.getInfoByCode(arg2.delBossId).boss.name);
                }
            }
            return "<textFormat leading=\'5\'>" + HTMLUtil.addColor(loc1, "#01FF10") + "</textFormat>";
        }

        /* internal  */getTopTimeText(arg1: SMagicTowerInfo, arg2: TMagicTowerConfig): string
        {
            var loc1="";
            if (arg1.floor > 0 && arg2.haveBoss == 1) 
            {
                loc1 = loc1 + (HTMLUtil.addColor(Language.getString(60077), "#FFFF00") + HTMLUtil.addColor(arg1.bestTime != 0 ? RemainTimeTool.getRemainTimeBySeconds(arg1.bestTime, true) : Language.getString(60078), "#FF01DE"));
                loc1 = loc1 + HTMLUtil.addColor(arg1.bestPlayerName == "" ? "" : "（" + arg1.bestPlayerName + "）", "#FF01DE");
            }
            return loc1;
        }

        /* internal  */getRemainBossText(arg1: SMagicTowerInfo, arg2: TMagicTowerConfig): string
        {
            var loc2=0;
            var loc1="";
            if (arg1.floor > 0) 
            {
                loc2 = arg1.totalBossNum - arg1.killBossNum;
                loc1 = HTMLUtil.addColor(Language.getString(60079), "#FFFF00") + HTMLUtil.addColor(loc2 + "/" + arg1.totalBossNum, "#FE7E01");
            }
            return loc1;
        }

        /* internal  */getAwardExpText(arg1: SMagicTowerInfo, arg2: TMagicTowerConfig): string
        {
            var loc1="";
            loc1 = loc1 + (Language.getString(60082) + arg2.rewardExp);
            if (arg1.expRate > 100) 
            {
                loc1 = loc1 + (" +" + int(arg2.rewardExp * (arg1.expRate - 100) / 100));
            }
            loc1 = loc1 + "\n";
            loc1 = loc1 + (Language.getString(60083) + arg1.totalExp);
            if (arg1.expRate > 100) 
            {
                loc1 = loc1 + (" +" + int(arg1.totalExp * (arg1.expRate - 100) / 100));
            }
            return "<textFormat leading=\'5\'>" + HTMLUtil.addColor(loc1, GlobalStyle.color1) + "</textFormat>";
        }

        /* internal  */getAwardItems(arg1: TMagicTowerConfig): Array<any>
        {
            var loc2=0;
            var loc3=null;
            var loc4=0;
            var loc1=[];
            if (arg1.awardItems != "") 
            {
                loc3 = arg1.awardItems.split("#");
                loc4 = 0;
                while (loc4 < loc3.length) 
                {
                    loc2 = parseInt(loc3[loc4]);
                    if (loc2 > 0) 
                    {
                        loc1.push(new ItemData(loc2));
                    }
                    ++loc4;
                }
            }
            return loc1;
        }

        /* internal  */getFirstAwardItems(arg1: TMagicTowerConfig): Array<any>
        {
            var loc2=0;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=0;
            var loc1=[];
            if (arg1.firstReward != "") 
            {
                loc5 = arg1.firstReward.split("#");
                loc6 = 0;
                while (loc6 < loc5.length) 
                {
                    if (loc5[loc6] && !(loc5[loc6] == "")) 
                    {
                        loc4 = (loc5[loc6] as string).split(",");
                        loc2 = parseInt(loc4[0]);
                        if (loc2 > 0) 
                        {
                            (loc3 = new ItemData(loc2)).itemAmount = parseInt(loc4[1]);
                            loc1.push(loc3);
                        }
                    }
                    ++loc6;
                }
            }
            return loc1;
        }

        protected updatePosition(): void
        {
            var loc1=5;
            this._warFareLabel.y = loc1;
            loc1 = loc1 + this._warFareLabel.height;
            this._condition.y = loc1;
            loc1 = loc1 + this._condition.height;
            this._conditionLabel.y = loc1;
            loc1 = loc1 + (this._conditionLabel.height + 5);
            this._remainTimeLabel.y = loc1;
            this._remainTime.y = loc1;
            loc1 = loc1 + this._remainTime.height;
            this._tipsLabel.y = loc1;
            loc1 = loc1 + (this._tipsLabel.height + 5);
            this._passedTimeLabel.y = loc1;
            loc1 = loc1 + this._passedTimeLabel.height;
            this._topTimeLabel.y = loc1;
            loc1 = loc1 + this._topTimeLabel.height;
            this._remainBossLabel.y = loc1;
            loc1 = loc1 + this._remainBossLabel.height;
            this._splitLine.y = loc1 + 5;
            loc1 = loc1 + (this._splitLine.height + 10);
            this._expAward.y = loc1;
            loc1 = loc1 + this._expAward.height;
            this._expAwardText.y = loc1;
            loc1 = loc1 + (this._expAwardText.height + 5);
            this._itemAwardText.y = loc1;
            loc1 = loc1 + this._itemAwardText.height;
            this._itemAward.y = loc1 + 5;
            loc1 = loc1 + this._itemAward.height;
            this._splitLine2.y = loc1 + 5;
            loc1 = loc1 + (this._splitLine2.height + 10);
            this._firstKillAwardText.y = loc1;
            loc1 = loc1 + this._firstKillAwardText.height;
            this._firstKillAward.y = loc1 + 5;
            loc1 = loc1 + this._firstKillAward.height;
            this._bg.height = this._bodySp.height + 10;
            return;
        }

        /* internal  */onSecTimerEvent(arg1: SecTimer): void
        {
            this.updateTimeLabel();
            this._useSec = this._useSec + 1;
            --this._remainSec;
            if (this._remainSec <= 0) 
            {
                this.stopTimer();
            }
            return;
        }

        public stopTimer(): void
        {
            if (this._secTimer) 
            {
                this._secTimer.stop();
                this._secTimer.dispose();
                this._secTimer = null;
            }
            return;
        }

        protected updateTimeLabel(): void
        {
            this._passedTimeLabel.htmlText = HTMLUtil.addColor(Language.getString(60080), "#FFFF00") + HTMLUtil.addColor(RemainTimeTool.getRemainTimeBySeconds(this._useSec, true), "#FE7E00");
            this._remainTime.htmlText = this.getRemainTimeText();
            this.updatePosition();
            return;
        }

        /* internal  */getRemainTimeText(): string
        {
            var loc1="";
            var loc2=this._remainSec < 0 ? 0 : _remainSec;
            if (loc2 > 99) 
            {
                loc1 = loc1 + HTMLUtil.addColor(RemainTimeTool.getRemainTimeBySeconds(loc2, true), "#FE7E00");
            }
            else 
            {
                loc1 = loc1 + ("<font face=\'" + FontUtil.stXingkaiName + "\' size=\'50\'>" + HTMLUtil.addColor(loc2 + "\t", "#FFFF00") + "</font>");
                loc1 = loc1 + ("<font face=\'" + FontUtil.stXingkaiName + "\' size=\'18\'>" + HTMLUtil.addColor(Language.getString(60364), "#FFFF00") + "</font>");
            }
            return loc1;
        }

        public clear(): void
        {
            this._warFareLabel.htmlText = "";
            this._conditionLabel.htmlText = "";
            this._tipsLabel.htmlText = "";
            this._passedTimeLabel.htmlText = "";
            this._remainTimeLabel.htmlText = "";
            this._remainTime.htmlText = "";
            this._topTimeLabel.htmlText = "";
            this._remainBossLabel.htmlText = "";
            this._itemAward.setAwardItems([]);
            this.stopTimer();
            return;
        }

        /* internal */ /* var */_splitLine2: ScaleBitmap;

        /* internal */ /* var */_firstKillAwardText: Object /* flash.text.TextField */;

        /* internal */ /* var */_firstKillAward: MagicTowerAwardItems;

        /* internal */ /* var */_hasPass: Boolean;

        protected /* var */_condition: Object /* flash.text.TextField */;

        protected /* var */_remainSec: int;

        /* internal */ /* var */_startDt: Date;

        /* internal */ /* var */_endDt: Date;

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        protected /* var */_useSec: int;

        /* internal */ /* var */_bodySp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_left: int=6;

        /* internal */ /* var */_warFareLabel: Object /* flash.text.TextField */;

        protected /* var */_conditionLabel: Object /* flash.text.TextField */;

        /* internal */ /* var */_tipsLabel: Object /* flash.text.TextField */;

        protected /* var */_passedTimeLabel: Object /* flash.text.TextField */;

        protected /* var */_remainTimeLabel: Object /* flash.text.TextField */;

        protected /* var */_remainTime: Object /* flash.text.TextField */;

        /* internal */ /* var */_topTimeLabel: Object /* flash.text.TextField */;

        protected /* var */_secTimer: SecTimer;

        /* internal */ /* var */_itemAward: MagicTowerAwardItems;

        protected /* var */_remainBossLabel: Object /* flash.text.TextField */;

        /* internal */ /* var */_splitLine: ScaleBitmap;

        protected /* var */_expAward: Object /* flash.text.TextField */;

        protected /* var */_expAwardText: Object /* flash.text.TextField */;

        /* internal */ /* var */_itemAwardText: Object /* flash.text.TextField */;
    }
